package com.congee02.service;

import com.congee02.service.UserService;
import com.congee02.service.impl.UserServiceImpl;
import com.congee02.spring.annoation.Component;
import com.congee02.spring.beans.BeanPostProcessor;

import java.util.Date;

/**
 * @author congee(congee02 @ 163.com)
 * @date 1/27/2023 12:34 PM
 */
@Component
public class CustomBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {

        System .out.println("[postProcessBeforeInitialization]");

        if (bean instanceof UserServiceImpl) {
            ((UserServiceImpl) bean).setDate(new Date());
        }

        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) {

        System.out.println("[postProcessAfterInitialization]");

        return bean;
    }
}
